﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DPS.Prototype.Model
{
    public enum Shift
    {
        Day,
        Night
    }

    public enum CapacityStatus
    {
        TotalAviralble = 0,
        PatialAviralble = 1,
        TotalOcuppy = 2,
        Locked = 3
    }

    public class Capacity:IComparable<Capacity>,IEquatable<Capacity>
    {
         
        public Shift Shift { get; set; }
        public DateTime ProductTime { get; set; }
        public DateTime StartTime { get; set; }
        public DateTime EndTime { get; set; }
        public ProdLine ProdLine { get; set; }
        public float UPH { get; set; }
        public int SortNo { get; set; }
        private float _occupiedUsage = 0.00f;
        private float _tobeOccupyUsage = 0.00f;

         

        public int Hours 
        {
            get { return (this.EndTime - this.StartTime).Hours; } 
        }

        public float TotalUsage
        {
            get { return this.Hours * this.UPH; }
        }

        List<string> OccupiedOrders
        {
            get;
            set;
        }

        public float OccupiedUsage
        {
            get
            {
                return this._occupiedUsage;
            }
            set {
                if (value > this.TotalUsage-this._occupiedUsage)
                {
                    throw new ArgumentOutOfRangeException();
                }
                else 
                {
                    this._occupiedUsage = value;
                    if (this.OccupyRate == 0.00f)
                    {
                        this.CapacityStatus = CapacityStatus.TotalAviralble;
                    }
                    else if(this.OccupyRate<1)
                    {
                        this.CapacityStatus = CapacityStatus.PatialAviralble;
                    }
                    else if (this.OccupyRate == 1.00f)
                    {
                        this.CapacityStatus = CapacityStatus.TotalOcuppy;
                    }
                }
            }
        }

        public float TobeOccupyUsage
        {
            get
            {
                return this._tobeOccupyUsage;
            }
            set
            {
                if (value > this.TotalUsage - this._occupiedUsage)
                {
                    throw new ArgumentOutOfRangeException();
                }
                else
                {
                    this._tobeOccupyUsage = value;
                }
            }
        }

        public float OccupyRate
        {
            get { return this.OccupiedUsage / TotalUsage; }
        }

        public CapacityStatus CapacityStatus
        {
            get;
            set;
        }

        public int CompareTo(Capacity other)
        {
            bool compareProdLineResult = (this.ProdLine as IComparable<ProdLine>).CompareTo(other.ProdLine) == 0;
            bool compareSortNoResult = this.SortNo == other.SortNo;
            return (compareProdLineResult && compareSortNoResult) ? 0 : -1;
        }

        public bool Equals(Capacity other)
        {
            return CompareTo(other) == 0;
        }

        public Capacity Next
        {
            get;
            set;
        }

        public Capacity Previous
        {
            get;
            set;
        }
     
    }
}
